<?php
namespace Association\Controller;
use Think\Controller;
class LoginController extends Controller {
	
	
	
    function login(){
		if(IS_POST){
			if(I('post.uname') && I('post.pword')){
				$db = M("master");
				$uname = I('post.uname');
				$pword = md5(I('post.pword'));
				//$code = I('post.code');
				
				
				/*
				if(check_verify($code) == null){
					$this -> error("验证码错误",'',2);
					exit();
				}
				*/
				$sql = $db -> where("username = '$uname' and password = '$pword'") -> find();
				if($sql){
					//dump($sql);
					cookie('masterid',$sql['id'],0); // 指定cookie保存时间
					var_dump(cookie('uid'));
					//echo U("/index");
					$this->success('登陆成功',"/Association");
				}else{
					$this -> error("用户名或者密码错误",'',2);
				}
			}else{
				$this -> error("用户名或者密码为空",'',2);
				
			}
			
		}else{
			//echo  I('cookie.uid');
			//cookie(null);
			$this-> display('./login');
		}
	}
	
	function register(){
	
	}
	
	function forgetpwd(){
	
	}
	
	function out(){
		cookie('masterid',null);
		$this->success('退出',"Association/Login/Login");
		
	}
	
	function Verify(){	//验证码
		$config = array(
			'length'	=>    4,     // 验证码位数
			'useNoise'	=>    false, // 关闭验证码杂点
			'fontSize'	=>	'15',
			//'imageH'	=>	'25',
			'useCurve' => 'false',	
		);
		$Verify = new \Think\Verify($config);
		$Verify->entry();
		
		//$code = I('post.code');
		//$verify->check($code, $id);
		
	}
	
}